<?php

class Control_Model_Table_Portfolio extends Zend_Db_Table_Abstract {

    protected $_name = 'portfolio_content';

    public function getDataID($id) {
        $id = (int) $id;
        $row = $this->fetchRow('id =' . $id);
        if (!$row) {
            //           throw new Exception("Count not find row $id");
        } else {
            return $row->toArray();
        }
    }

    public function addData($logo, $img1, $img2, $img3, $logo_link, $name, $link, $langs, $about, $class) {
        $data = array(
            'logo' => $logo,
            'logo_link' => $logo_link,
            'name' => $name,
            'link' => $link,
            'langs' => $langs,
            'about' => $about,
            'class' => $class
        );

                if ($img3 != "") {
            $logo3 = array('img3' => $img3);
            $data = $logo3 + $data;
        }
        if ($img2 != "") {
            $logo2 = array('img2' => $img2);
            $data = $logo2 + $data;
        }
        if ($img1 != "") {
            $logo1 = array('img1' => $img1);
            $data = $logo1 + $data;
        }

        $this->insert($data);
    }

    public function getAll() {
        $select = $this->select();
        $select->order('id DESC');
        $Data = $this->_db->query($select)->fetchAll();
        return $Data;
    }

    public function updateData($id, $logo, $img1, $img2, $img3, $logo_link, $name, $link, $langs, $about, $class) {
 //      Zend_Debug::dump($logo);Zend_Debug::dump($img1);Zend_Debug::dump($img2);exit();
        $data = array(
            'logo_link' => $logo_link,
            'name' => $name,
            'link' => $link,
            'langs' => $langs,
            'about' => $about,
            'class' => $class
        );
        if ($img3 != "") {
            $logo3 = array('img3' => $img3);
            $data = $logo3 + $data;
        }
        if ($img2 != "") {
            $logo2 = array('img2' => $img2);
            $data = $logo2 + $data;
        }
        if ($img1 != "") {
            $logo1 = array('img1' => $img1);
            $data = $logo1 + $data;
        }
        if ($logo != "") {
            $logo = array('logo' => $logo);
            $data = $logo + $data;
        }

//       Zend_Debug::dump($data);exit();
        $this->update($data, 'id= ' . (int) $id);
    }

    public function deleteData($id) {
        $this->delete('id =' . (int) $id);
    }

}

